#include "iostream"
#include "cstring"

using namespace std;

class MyTime
{
private:
  int hour, minute, second;

public:
  void SetTime(int, int, int); //没有形参名的函数只用来声明，然而到定义的时候，一般情况下都有形参名称
  void print_12();
  void print_24();
};

void MyTime::SetTime(int a, int b, int c)
{
  hour = (a >= 0 && a < 24) ? a : 0;
  minute = (b >= 0 && b < 60) ? b : 0;
  second = (c >= 0 && c < 60) ? c : 0;
}

void MyTime::print_12()
{
  if (hour < 12)
    printf("%02d:%02d:%02d AM\n", hour, minute, second);
  else
    printf("%02d:%02d:%02d PM\n", hour - 12, minute, second);
}

void MyTime::print_24()
{
  printf("%02d:%02d:%02d\n", hour, minute, second);
}

int main()
{
  MyTime t;
  int a, b, c;
  cin >> a >> b >> c;
  t.SetTime(a, b, c);
  t.print_12();
  t.print_24();
  return 0;
}